<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script src="../vue.js">
    </script>

<div class="app">
    <!--在这里会默认接收子组件发送的自定义事件里面的参数-->
    <test1 @item-click="cpnclick" ></test1>
</div>

    <template id="myCpn">
        <div>
            <button v-for="item in categories" @click="btnClick(item)">{{item.name}}</button>
        </div>

    </template>

    <script>

    const cpn1 = {
        template: '#myCpn',
        data () {
            return {
                categories: [
                    {id:01,name:'热门推荐'},
                    {id:02,name:'家电'},
                    {id:03,name:'水电'},
                    {id:04,name:'雷电'},
                    {id:05,name:'理想'}
                ]
            }
        },
        methods: {
            btnClick(item){
                //发射自定义事件
                this.$emit('item-click',item)
            }
        }
    }

    const app = new Vue({
        el: '.app',
        components: {
            "test1":cpn1
        },
        methods: {
            cpnclick(item){
                console.log('cpnClick',item)
            }
        }
    })




    </script>


    
</body>
</html>